package cn.cyh.order.controller;

import cn.cyh.basic.uitls.AJaxResult;
import cn.cyh.basic.uitls.LoginContext;
import cn.cyh.basic.uitls.PageList;
import cn.cyh.order.domain.AdoptOrder;
import cn.cyh.order.query.AdoptOrderQuery;
import cn.cyh.order.service.IAdoptOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/adoptOrder")
public class AdoptOrderController {

    @Autowired
    private IAdoptOrderService adoptOrderService;
    @PostMapping("/submit")
    public AJaxResult submit(@RequestBody Map<String,Object> params, HttpServletRequest request){
        try {
            String payData = adoptOrderService.sumbit(params, LoginContext.currentLongInfo(request));
            return AJaxResult.myself().setResultObj(payData);
        } catch (Exception e) {
            e.printStackTrace();
            return AJaxResult.myself().setSuccess(false).setMsg("下单失败"+e.getMessage());
        }

    }

    /**
     * 平台员工
     * @param query
     * @param request
     * @return
     */
    @PostMapping("/admin")
    public PageList<AdoptOrder> admin(@RequestBody AdoptOrderQuery query,HttpServletRequest request){
       return adoptOrderService.admin(query,LoginContext.currentLongInfo(request));
    }

    /**
     * 前端用户
     * @param query
     * @param request
     * @return
     */
    @PostMapping("/user")
    public PageList<AdoptOrder> user(@RequestBody AdoptOrderQuery query,HttpServletRequest request){
       return adoptOrderService.user(query,LoginContext.currentLongInfo(request));
    }

    @GetMapping("/{id}")
    public AdoptOrder getInfo(@PathVariable("id") Long id){
        return adoptOrderService.loadById(id);
    }

}
